{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 莺尾花样例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename'])\n",
      "[[5.1 3.5 1.4 0.2]\n",
      " [4.9 3.  1.4 0.2]\n",
      " [4.7 3.2 1.3 0.2]\n",
      " [4.6 3.1 1.5 0.2]\n",
      " [5.  3.6 1.4 0.2]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_iris\n",
    "iris_data = load_iris()\n",
    "print(iris_data.keys())\n",
    "print(iris_data['data'][:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 将数据集随机分成训练集和测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 将数据集拆分（75%作为训练集，25%作为测试集）\n",
    "# 使用train_test_split()方法来将数据集打乱并拆分\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(iris_data['data'],iris_data['target'], random_state=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构建一个knn模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(n_neighbors=1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用KNN构建第一个模型\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "# 这里这是邻居数量为1\n",
    "knn = KNeighborsClassifier(n_neighbors=1)\n",
    "# 使用训练集训练模型\n",
    "knn.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "品种对应标签:[0]\n",
      "品种:['setosa']\n"
     ]
    }
   ],
   "source": [
    "# 随机使用一个数据来测试一下\n",
    "X_new = np.array([[5,2.9,1,0.27]])\n",
    "result = knn.predict(X_new)\n",
    "print(\"品种对应标签:\" + str(result))\n",
    "print(\"品种:\" + str(iris_data['target_names'][result]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 检测模型的精度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "精度为：0.9736842105263158\n",
      "精度为：0.9736842105263158\n"
     ]
    }
   ],
   "source": [
    "# 进行评估\n",
    "y_pred = knn.predict(X_test)\n",
    "print(\"精度为：\" + str(np.mean(y_pred == y_test)))\n",
    "# 或者\n",
    "print(\"精度为：\" + str(knn.score(X_test, y_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD4CAYAAADlwTGnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3deXxU9bn48c+TBUIIE0IIkElYIrJlAgSIaIVaW4sFtYL4c2GpXmuLWnDtVbn2erXtbS+1rlSEi1v1qrhvtdQNq9RdCAGzIasQ1rAGCJDt+f0xBxxjIJMwyZnJPO/Xa14zc873nPNMCPPkfL/nPF9RVYwxxkSfGLcDMMYY4w5LAMYYE6UsARhjTJSyBGC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9092QjroWeNrpblkLXOFyPAA4fdljgKvcjuUIVf1MRF4E8vF3sSwjfMpCvCQiqUA1MF1Vd4dqx23+MlBjjDENsy4gY4yJUpYAjDEmSlkCMMaYKGUJwBhjopQlAGOMiVKWAIwxJkpZAjDGmCj1/wHKufOGWzF+NgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 取不同的K值，实现-----其精度曲线\n",
    "x = [i for i in range(1,10)]\n",
    "train_result = list()\n",
    "pred_result = list()\n",
    "for i in x:\n",
    "    knn = KNeighborsClassifier(i)\n",
    "    knn.fit(X_train, y_train)\n",
    "    train_result.append(knn.score(X_train, y_train))\n",
    "    pred_result.append(knn.score(X_test, y_test))\n",
    "plt.plot(x, train_result, label = \"train_result\")\n",
    "plt.plot(x, pred_result, label = \"pred_result\")\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
